from sqlalchemy import Column, String, create_engine, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import time, math

Base = declarative_base()


class Webs(Base):
    __tablename__ = 'webs'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(50), nullable=False)
    base_url = Column(String(100), nullable=False)
    create_time = Column(Integer, nullable=False, default=math.ceil(time.time()))


engine = create_engine('sqlite:///test.db', echo=True)

Base.metadata.create_all(engine)

Dbsession = sessionmaker(bind=engine)

session = Dbsession()

if __name__ == "__main__":
    new_web = Webs(name="东莞智方设计", base_url="http://www.dgzfsj.com")

    session.add(new_web)

    session.commit()

    session.close()
